<template>
	<view>
		<swiper-tab-head
		:tabBars="tabBars" 
		:tabIndex="tabIndex"
		@tabtap="tabtap"></swiper-tab-head>
		
		<view class="uni-tab-bar">
			<swiper class="swiper-box" 
			:style="{height:swiperheight+'px'}" 
			:current="tabIndex"
			@change="tabChange">
				<swiper-item v-for="(items,index) in newsList" :key="index">
					<scroll-view scroll-y class="list" @scrolltolower="loadmore(index)">
						<template v-if="items.list.length>0">
							<!-- 话题列表 -->
							<view class="topic-view">
								<block v-for="(item,index1) in items.list" :key="index1">
									<topic-list :item="item" :index="index1"></topic-list>
								</block>
							</view>
							<!-- 上拉加载 -->
							<load-more :loadtext="items.loadtext"></load-more>
						</template>
						<!-- 无内容默认 -->
						<template v-else>
							<no-thing></no-thing>
						</template>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import swiperTabHead from "../../components/index/swiper-tab-head.vue";
	import noThing from "../../components/common/no-thing.vue";
	import loadMore from "../../components/common/load-more.vue";
	import topicList from "../../components/news/topic-list.vue"
	export default {
		components:{
			swiperTabHead,
			noThing,
			loadMore,
			topicList
		},
		data() {
			return {
				swiperheight:500,
				tabIndex:0,
				tabBars:[
					{name:'关注',id:'guanzhu'},
					{name:'推荐',id:'tuijian'},
					{name:'体育',id:'tiyu'},
					{name:'热点',id:'redian'},
					{name:'财经',id:'caijing'},
					{name:'娱乐',id:'yule'}
				],
				newsList:[
					{
						loadtext:"上拉加载更多",
						list:[
							{
								titlepic:"../../static/img/iphone12.jpg",
								title:"iphone12 Pro",
								desc:"iphone12 Pro上手实测",
								totalnum:666,
								todaynum:33
							},
							{
								titlepic:"../../static/img/yuanshen.jpg",
								title:"原神角色测评(钟离篇)",
								desc:"建议人手一个，立帖为证，不抽后悔",
								totalnum:222,
								todaynum:11
							},
							{
								titlepic:"../../static/img/wangzhe.jpg",
								title:"王者荣耀",
								desc:"我是话题描述",
								totalnum:333,
								todaynum:20
							},
							{
								titlepic:"../../static/img/douyin.jpg",
								title:"抖音",
								desc:"抖音就是一个平平无奇的,但是我每天都会刷到手机没电的APP",
								totalnum:180,
								todaynum:99
							},
							{
								titlepic:"../../static/img/douyin.jpg",
								title:"抖音",
								desc:"抖音就是一个平平无奇的,但是我每天都会刷到手机没电的APP",
								totalnum:180,
								todaynum:99
							},
							{
								titlepic:"../../static/img/douyin.jpg",
								title:"抖音",
								desc:"抖音就是一个平平无奇的,但是我每天都会刷到手机没电的APP",
								totalnum:180,
								todaynum:99
							},
							{
								titlepic:"../../static/img/douyin.jpg",
								title:"抖音",
								desc:"抖音就是一个平平无奇的,但是我每天都会刷到手机没电的APP",
								totalnum:180,
								todaynum:99
							},
						]
					},
					{
						loadtext:"上拉加载更多",
						list:[
							{
								titlepic:"../../static/img/iphone12.jpg",
								title:"iphone12 Pro",
								desc:"iphone12 Pro上手实测",
								totalnum:666,
								todaynum:33
							},
							{
								titlepic:"../../static/img/yuanshen.jpg",
								title:"原神角色测评(钟离篇)",
								desc:"建议人手一个，立帖为证，不抽后悔",
								totalnum:222,
								todaynum:11
							},
							{
								titlepic:"../../static/img/wangzhe.jpg",
								title:"王者荣耀",
								desc:"我是话题描述",
								totalnum:333,
								todaynum:20
							},
							{
								titlepic:"../../static/img/douyin.jpg",
								title:"抖音",
								desc:"抖音就是一个平平无奇的,但是我每天都会刷到手机没电的APP",
								totalnum:180,
								todaynum:99
							},
							{
								titlepic:"../../static/img/iphone12.jpg",
								title:"iphone12 Pro",
								desc:"iphone12 Pro上手实测",
								totalnum:666,
								todaynum:33
							},
							{
								titlepic:"../../static/img/yuanshen.jpg",
								title:"原神角色测评(钟离篇)",
								desc:"建议人手一个，立帖为证，不抽后悔",
								totalnum:222,
								todaynum:11
							},
							{
								titlepic:"../../static/img/wangzhe.jpg",
								title:"王者荣耀",
								desc:"我是话题描述",
								totalnum:333,
								todaynum:20
							},
						]
					},
					{
						loadtext:"上拉加载更多",
						list:[]
					},
					{
						loadtext:"上拉加载更多",
						list:[]
					},
					{
						loadtext:"上拉加载更多",
						list:[]
					}
				]
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success:(res)=> {
					let height = res.windowHeight - uni.upx2px(100)
					this.swiperheight = height
				}
			})
		},
		methods: {
			// 上拉加载
			loadmore(index){
				if(this.newsList[index].loadtext!=='上拉加载更多'){return;}
				//修改状态
				this.newsList[index].loadtext="加载中...";
				//获取数据
				setTimeout(()=>{
					//获取完成
					let obj = {
								titlepic:"../../static/img/iphone12.jpg",
								title:"iphone12 Pro",
								desc:"iphone12 Pro上手实测",
								totalnum:666,
								todaynum:33
							}
					this.newsList[index].list.push(obj)
					this.newsList[index].loadtext='上拉加载更多'
				},1000)
			},
			// tabbar点击事件
			tabtap(index){
				this.tabIndex=index
			},
			// 滑动事件
			tabChange(e){
				this.tabIndex = e.detail.current
			}
		}
	}
</script>

<style>
.topic-view {
	padding: 0 20upx;
}
</style>
